﻿<!DOCTYPE html>
<html>
<head>
	<script src="../../jsrender.js" type="text/javascript"></script>
	<link href="../resources/demos.css" rel="stylesheet" type="text/css" />

	<link href="../resources/movielist.css" rel="stylesheet" type="text/css" />
</head>
<body>
<a href="../demos.html">JsRender Demos</a><br />

<h3>JsRender without jQuery</h3>

<pre>
    jsviews.templates({
        movieTemplate: document.getElementById( "movieTemplate" ).innerHTML,
        ...
    });

    document.getElementById( "movieList" ).innerHTML = jsviews.render.movieTemplate( movies );
</pre>

<script id="movieTemplate" type="text/x-jsrender">
	<tr>
		<td>{{:title}}</td>
		<td>{{sort languages tmpl="sortedTemplate"/}}</td>
		<td>{{sort languages reverse=true}}
				<div>
					<b>{{:name}}</b>
				</div>
			{{/sort}}
		</td>
	</tr>
</script>

<script id="sortedTemplate" type="text/x-jsrender">
	<div>{{:name}}</div>
</script>

<div id="movieList"></div>

<script type="text/javascript">

	jsviews.tags({

		sort: function( array ){
			var ret = "";
			if ( this.props.reverse ) {
				// Render in reverse order
				for ( var i = array.length; i; i-- ) {
					ret += this.tmpl.render( array[ i - 1 ] );
				}
			} else {
				// Render in original order
				ret += this.tmpl.render( array );
			}
			return ret;
		}

	});

	var movies = [
		{
			title: "Meet Joe Black",
			languages: [
				{ name: "English" },
				{ name: "French" }
			]
		},
		{
			title: "Eyes Wide Shut",
			languages: [
				{ name: "French" },
				{ name: "German" },
				{ name: "Spanish" }
			]
		}
	];

	jsviews.templates({
		movieTemplate: document.getElementById( "movieTemplate" ).innerHTML,
		sortedTemplate: document.getElementById( "sortedTemplate" ).innerHTML
	});

	document.getElementById( "movieList" ).innerHTML =
		"<table><thead><tr><th>Title</th><th>Original order</th><th>Reverse order</th></tr></thead><tbody>" + jsviews.render.movieTemplate( movies ) + "</tbody></table>";
</script>

</body>
</html>
